<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Potential Incompatibilities with Earlier Versions &mdash; PyQt snapshot-4.9.5-9eb6aac99275 Reference Guide</title>
    <link rel="stylesheet" href="_static/default.css" type="text/css" />
    <link rel="stylesheet" href="_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '#',
        VERSION:     'snapshot-4.9.5-9eb6aac99275',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="_static/jquery.js"></script>
    <script type="text/javascript" src="_static/doctools.js"></script>
    <link rel="shortcut icon" href="_static/logo_tn.ico"/>
    <link rel="top" title="PyQt snapshot-4.9.5-9eb6aac99275 Reference Guide" href="index.html" />
    <link rel="next" title="Installing PyQt" href="installation.html" />
    <link rel="prev" title="Introduction" href="introduction.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="installation.html" title="Installing PyQt"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="introduction.html" title="Introduction"
             accesskey="P">previous</a> |</li>
        <li><a href="index.html">PyQt snapshot-4.9.5-9eb6aac99275 Reference Guide</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="potential-incompatibilities-with-earlier-versions">
<h1>Potential Incompatibilities with Earlier Versions<a class="headerlink" href="#potential-incompatibilities-with-earlier-versions" title="Permalink to this headline">¶</a></h1>
<div class="section" id="pyqt-v4-9-2">
<h2>PyQt v4.9.2<a class="headerlink" href="#pyqt-v4-9-2" title="Permalink to this headline">¶</a></h2>
<div class="section" id="qpynullvariant">
<h3>QPyNullVariant<a class="headerlink" href="#qpynullvariant" title="Permalink to this headline">¶</a></h3>
<p>In previous versions a <tt class="docutils literal"><span class="pre">QPyNullVariant</span></tt> would always evaluate to <tt class="xref docutils literal"><span class="pre">True</span></tt>
when converted to a bool.</p>
<p>In this version a <tt class="docutils literal"><span class="pre">QPyNullVariant</span></tt> will always evaluate to <tt class="xref docutils literal"><span class="pre">False</span></tt> when
converted to a bool.  This makes it behave like <tt class="xref docutils literal"><span class="pre">None</span></tt> in these
circumstances.</p>
</div>
</div>
<div class="section" id="pyqt-v4-8-3">
<h2>PyQt v4.8.3<a class="headerlink" href="#pyqt-v4-8-3" title="Permalink to this headline">¶</a></h2>
<div class="section" id="sql-models">
<h3>SQL Models<a class="headerlink" href="#sql-models" title="Permalink to this headline">¶</a></h3>
<p>In previous versions, when using v2 of the QVariant API (the default for Python
v3), there was no way to represent a null <tt class="docutils literal"><span class="pre">QVariant</span></tt>.  Therefore when reading
values of certain types from an SQL model it was impossible to distinguish
between, for example, a null integer and an integer with the value zero.</p>
<p>In this version the <tt class="docutils literal"><span class="pre">QPyNullVariant</span></tt> class is used to represent a null
QVariant.  Therefore the object read from an SQL model may now be a
<tt class="docutils literal"><span class="pre">QPyNullVariant</span></tt> instance.</p>
<p>A null <tt class="docutils literal"><span class="pre">QVariant</span></tt> is only converted to a <tt class="docutils literal"><span class="pre">QPyNullVariant</span></tt> if the underlying
C++ type of the <tt class="docutils literal"><span class="pre">QVariant</span></tt> cannot be tested for null, i.e. it does not
implement an <tt class="docutils literal"><span class="pre">isNull()</span></tt> method.  This ensures that existing code that uses
non-SQL models will continue to work unchanged.</p>
</div>
</div>
<div class="section" id="pyqt-v4-8">
<h2>PyQt v4.8<a class="headerlink" href="#pyqt-v4-8" title="Permalink to this headline">¶</a></h2>
<div class="section" id="qvariantlist">
<h3>QVariantList<a class="headerlink" href="#qvariantlist" title="Permalink to this headline">¶</a></h3>
<p>In previous versions PyQt would always try and convert a Python list to a
<tt class="docutils literal"><span class="pre">QVariantList</span></tt>.  In this version PyQt will first try to convert it to a
<tt class="docutils literal"><span class="pre">QVariant</span></tt> containing a <tt class="docutils literal"><span class="pre">QList&lt;QObject</span> <span class="pre">*&gt;</span></tt>, but only if
<tt class="docutils literal"><span class="pre">QList&lt;QObject</span> <span class="pre">*&gt;</span></tt> has been registered with Qt as a meta-type.</p>
<p>Normally it is only the <tt class="xref docutils literal"><span class="pre">QtDeclarative</span></tt> module that registers this
meta-type and so the behaviour of existing applications should be unchanged.
It is possible however that you might observe different conversion behaviour
after importing the <tt class="xref docutils literal"><span class="pre">QtDeclarative</span></tt> module.</p>
</div>
</div>
<div class="section" id="pyqt-v4-7-4">
<h2>PyQt v4.7.4<a class="headerlink" href="#pyqt-v4-7-4" title="Permalink to this headline">¶</a></h2>
<div class="section" id="pyqtsignal-with-dict-and-list">
<h3><a title="PyQt4.QtCore.pyqtSignal" class="reference external" href="new_style_signals_slots.html#PyQt4.QtCore.pyqtSignal"><tt class="xref docutils literal"><span class="pre">pyqtSignal()</span></tt></a> with dict and list<a class="headerlink" href="#pyqtsignal-with-dict-and-list" title="Permalink to this headline">¶</a></h3>
<p>In previous versions a Qt signal defined using
<a title="PyQt4.QtCore.pyqtSignal" class="reference external" href="new_style_signals_slots.html#PyQt4.QtCore.pyqtSignal"><tt class="xref docutils literal"><span class="pre">pyqtSignal()</span></tt></a> that had an argument specified as a dict then,
when emitting a value, PyQt would try and convert the value to a
<tt class="docutils literal"><span class="pre">QVariantMap</span></tt> if possible.  If it wasn&#8217;t possible, normally because the dict
had non-string keys, then the value would be left as a dict object.</p>
<p>In this version PyQt will not attempt to convert the value to a <tt class="docutils literal"><span class="pre">QVariantMap</span></tt>
and will always leave it as a dict object.  If you want the value to be
converted to a <tt class="docutils literal"><span class="pre">QVariantMap</span></tt> then define the signal argument as
<tt class="docutils literal"><span class="pre">'QVariantMap'</span></tt>.</p>
<p>The same applies to conversions between lists and <tt class="docutils literal"><span class="pre">QVariantList</span></tt>.</p>
</div>
</div>
<div class="section" id="pyqt-v4-7-1">
<h2>PyQt v4.7.1<a class="headerlink" href="#pyqt-v4-7-1" title="Permalink to this headline">¶</a></h2>
<div class="section" id="qvariant">
<h3>QVariant<a class="headerlink" href="#qvariant" title="Permalink to this headline">¶</a></h3>
<p>This version introduces a slight incompatibility in the conversion between
sub-classes of standard Python types and <tt class="docutils literal"><span class="pre">QVariant</span></tt>.</p>
<p>Take, for example, the following code:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">PyQt4.QtCore</span> <span class="kn">import</span> <span class="n">QVariant</span>

<span class="k">class</span> <span class="nc">MyFloat</span><span class="p">(</span><span class="nb">float</span><span class="p">):</span>
    <span class="k">pass</span>

<span class="n">myfloat</span> <span class="o">=</span> <span class="n">MyFloat</span><span class="p">(</span><span class="mf">5.0</span><span class="p">)</span>
<span class="n">variant</span> <span class="o">=</span> <span class="n">QVariant</span><span class="p">(</span><span class="n">myfloat</span><span class="p">)</span>
</pre></div>
</div>
<p>With this version of PyQt <tt class="docutils literal"><span class="pre">myfloat</span></tt> will be converted in such a way as to
preserve any additional attributes (including methods) and will not be
converted to a C++ <tt class="docutils literal"><span class="pre">double</span></tt>.  In other words, the following assertions are
true:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">type</span><span class="p">()</span> <span class="o">!=</span> <span class="n">QVariant</span><span class="o">.</span><span class="n">Double</span><span class="p">)</span>
<span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">toPyObject</span><span class="p">()</span> <span class="ow">is</span> <span class="n">myfloat</span><span class="p">)</span>
</pre></div>
</div>
<p>Prior to this version <tt class="docutils literal"><span class="pre">myfloat</span></tt> would be converted to a C++ <tt class="docutils literal"><span class="pre">double</span></tt>.  In
other words, the following assertions would be true:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">type</span><span class="p">()</span> <span class="o">==</span> <span class="n">QVariant</span><span class="o">.</span><span class="n">Double</span><span class="p">)</span>
<span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">toPyObject</span><span class="p">()</span> <span class="o">==</span> <span class="n">myfloat</span><span class="p">)</span>
<span class="k">assert</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">toPyObject</span><span class="p">())</span> <span class="ow">is</span> <span class="nb">float</span><span class="p">)</span>
</pre></div>
</div>
<p>The same change also affects objects that implement the sequence protocol.
Prior to this version such an object would be converted to a <tt class="docutils literal"><span class="pre">QVariantList</span></tt>
which would mean that it was converted back to a Python <tt class="docutils literal"><span class="pre">list</span></tt> rather than to
the original type.</p>
</div>
</div>
<div class="section" id="pyqt-v4-5">
<h2>PyQt v4.5<a class="headerlink" href="#pyqt-v4-5" title="Permalink to this headline">¶</a></h2>
<div class="section" id="id1">
<h3>QVariant<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<p>This version introduces a slight incompatibility in the conversion between
Python sub-classes of certain Qt classes and <tt class="docutils literal"><span class="pre">QVariant</span></tt>.  The Qt classes
affected are those that <tt class="docutils literal"><span class="pre">QVariant</span></tt> has explicit support for, e.g. <tt class="docutils literal"><span class="pre">QSize</span></tt>,
<tt class="docutils literal"><span class="pre">QBitmap</span></tt>.</p>
<p>Take, for example, the following code:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">PyQt4.QtCore</span> <span class="kn">import</span> <span class="n">QSize</span><span class="p">,</span> <span class="n">QVariant</span>

<span class="k">class</span> <span class="nc">MySize</span><span class="p">(</span><span class="n">QSize</span><span class="p">):</span>
    <span class="k">pass</span>

<span class="n">mysize</span> <span class="o">=</span> <span class="n">MySize</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">)</span>
<span class="n">variant</span> <span class="o">=</span> <span class="n">QVariant</span><span class="p">(</span><span class="n">mysize</span><span class="p">)</span>
</pre></div>
</div>
<p>With this version of PyQt <tt class="docutils literal"><span class="pre">mysize</span></tt> will be converted in such a way as to
preserve any additional attributes (including methods) and will not be
converted to a C++ <tt class="docutils literal"><span class="pre">QSize</span></tt> instance.  In other words, the following
assertions are true:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">type</span><span class="p">()</span> <span class="o">!=</span> <span class="n">QVariant</span><span class="o">.</span><span class="n">Size</span><span class="p">)</span>
<span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">toPyObject</span><span class="p">()</span> <span class="ow">is</span> <span class="n">mysize</span><span class="p">)</span>
</pre></div>
</div>
<p>Prior to this version <tt class="docutils literal"><span class="pre">mysize</span></tt> would be converted to a C++ <tt class="docutils literal"><span class="pre">QSize</span></tt>
instance.  In other words, the following assertions would be true:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">type</span><span class="p">()</span> <span class="o">==</span> <span class="n">QVariant</span><span class="o">.</span><span class="n">Size</span><span class="p">)</span>
<span class="k">assert</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">toPyObject</span><span class="p">()</span> <span class="o">==</span> <span class="n">mysize</span><span class="p">)</span>
<span class="k">assert</span><span class="p">(</span><span class="nb">type</span><span class="p">(</span><span class="n">variant</span><span class="o">.</span><span class="n">toPyObject</span><span class="p">())</span> <span class="ow">is</span> <span class="n">QSize</span><span class="p">)</span>
</pre></div>
</div>
<p>It is hoped that this change of behaviour will not have a significant impact.
However if you need the old behaviour then simply create a copy of your
sub-class instance using the base class constructor as shown below:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="n">variant</span> <span class="o">=</span> <span class="n">QVariant</span><span class="p">(</span><span class="n">QSize</span><span class="p">(</span><span class="n">mysize</span><span class="p">))</span>
</pre></div>
</div>
<p>A similar issue also affects the conversion of the Python <tt class="docutils literal"><span class="pre">datetime</span></tt>,
<tt class="docutils literal"><span class="pre">date</span></tt> and <tt class="docutils literal"><span class="pre">time</span></tt> types to <tt class="docutils literal"><span class="pre">QVariant</span></tt>.  These are no longer converted to
the corresponding <tt class="docutils literal"><span class="pre">QDateTime</span></tt>, <tt class="docutils literal"><span class="pre">QDate</span></tt> and <tt class="docutils literal"><span class="pre">QTime</span></tt> classes.  The values
can be retrieved using <tt class="docutils literal"><span class="pre">QVariant.toPyObject()</span></tt>.  Again, the old behaviour can
be achieved using an explicit conversion to the Qt class before converting to
<tt class="docutils literal"><span class="pre">QVariant</span></tt>.</p>
<p>A further incompatible change is the handling of Python sub-classes of
<tt class="docutils literal"><span class="pre">QObject</span></tt>.  In previous versions <tt class="docutils literal"><span class="pre">QVariant.userType()</span></tt> would return an
internal type and an extra reference would be kept to the Python object.  In
the current version <tt class="docutils literal"><span class="pre">QVariant.userType()</span></tt> will correctly return
<tt class="docutils literal"><span class="pre">QMetaType.QObjectStar</span></tt> (or <tt class="docutils literal"><span class="pre">QMetaType.QWidgetStar</span></tt>) but an extra
reference to the Python object is not kept.  To avoid a potential crash you
should ensure that you keep a separate reference to the Python object, either
explicitly or implicitly by giving it a parent.</p>
</div>
<div class="section" id="pyrcc4-support-for-python-v3">
<h3><strong>pyrcc4</strong> Support for Python v3<a class="headerlink" href="#pyrcc4-support-for-python-v3" title="Permalink to this headline">¶</a></h3>
<p><strong>pyrcc4</strong> will now generate code for Python v3 when the new
<a class="reference external" href="resources.html#cmdoption-pyrcc4-py3"><em class="xref">-py3</em></a> command line option is used.  The generated code
will also work with Python v2.6 and later.</p>
<p>By default <strong>pyrcc4</strong> will generate code for all Python v2 versions but
you should use the new <a class="reference external" href="resources.html#cmdoption-pyrcc4-py2"><em class="xref">-py2</em></a> command line option to
enforce this in case the default is changed in the future.</p>
</div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <p class="logo"><a href="index.html">
              <img class="logo" src="_static/logo.png" alt="Logo"/>
            </a></p>
            <h3><a href="index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="#">Potential Incompatibilities with Earlier Versions</a><ul>
<li><a class="reference external" href="#pyqt-v4-9-2">PyQt v4.9.2</a><ul>
<li><a class="reference external" href="#qpynullvariant">QPyNullVariant</a></li>
</ul>
</li>
<li><a class="reference external" href="#pyqt-v4-8-3">PyQt v4.8.3</a><ul>
<li><a class="reference external" href="#sql-models">SQL Models</a></li>
</ul>
</li>
<li><a class="reference external" href="#pyqt-v4-8">PyQt v4.8</a><ul>
<li><a class="reference external" href="#qvariantlist">QVariantList</a></li>
</ul>
</li>
<li><a class="reference external" href="#pyqt-v4-7-4">PyQt v4.7.4</a><ul>
<li><a class="reference external" href="#pyqtsignal-with-dict-and-list"><tt class="docutils literal"><span class="pre">pyqtSignal()</span></tt> with dict and list</a></li>
</ul>
</li>
<li><a class="reference external" href="#pyqt-v4-7-1">PyQt v4.7.1</a><ul>
<li><a class="reference external" href="#qvariant">QVariant</a></li>
</ul>
</li>
<li><a class="reference external" href="#pyqt-v4-5">PyQt v4.5</a><ul>
<li><a class="reference external" href="#id1">QVariant</a></li>
<li><a class="reference external" href="#pyrcc4-support-for-python-v3"><strong>pyrcc4</strong> Support for Python v3</a></li>
</ul>
</li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="introduction.html"
                                  title="previous chapter">Introduction</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="installation.html"
                                  title="next chapter">Installing PyQt</a></p>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="installation.html" title="Installing PyQt"
             >next</a> |</li>
        <li class="right" >
          <a href="introduction.html" title="Introduction"
             >previous</a> |</li>
        <li><a href="index.html">PyQt snapshot-4.9.5-9eb6aac99275 Reference Guide</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2011 Riverbank Computing Limited.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.4.
    </div>
  </body>
</html>